home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 May / Macworld (1998-05).dmg / Shareware World / Comms & Internet / ProTERM_1.2.5.Install / ProTERM Mac1.2.5 / PT Resources / PT Process URL < prev    next >
Text File  |  1996-07-13  |  2KB  |  116 lines

  1. //
  2. // this file should be located in the PT Resources folder
  3. //
  4. // version 1.0 - jan 17, 1996
  5. //
  6.  
  7.  
  8. //
  9. // process url reference
  10. //
  11. FUNC main(STR kind, STR url, STR opt)
  12. {
  13.  STR host,port,user,pass,upurl;
  14.  
  15.  IF (kind == "CONF") {
  16.   parse_ncsa(url,&host,&port,&user,&pass);
  17.   telnet_to(host,port,user,pass);
  18.   RETURN(0);
  19.  }
  20.  
  21.  IF ((STR_LEFT(url,1) == "<") && (STR_RIGHT(url,1) == ">")) {
  22.   url = STR_MID(url,1,STR_LEN(url)-2);
  23.  }
  24.  IF (STR_UPPER(STR_LEFT(url,4)) == "URL:") {
  25.   url = STR_MID(url,4);
  26.  }
  27.  upurl = STR_UPPER(url);
  28.  
  29.  IF ((kind == "GURL") && (STR_LEFT(upurl,7) == "TELNET:")) {
  30.   parse_telnet(url,&host,&port,&user,&pass);
  31.   telnet_to(host,port,user,pass);
  32.   RETURN(0);
  33.  }
  34.  
  35.  RETURN(0);
  36. }
  37.  
  38. // parse telnet info from NCSA Telnet CONF file
  39. FUNC parse_ncsa(STR file, STR host, STR port, STR user, STR pass)
  40. {
  41.  INT fd;
  42.  STR name;
  43.  
  44.  host = port = user = pass = "";
  45.  
  46.  fd = F_OPEN(file,"RW");
  47.  IO_SCANF(fd,'name= "%s"^m',name); 
  48.  IO_SCANF(fd,'host= "%s"^m',host);
  49.  IO_SCANF(fd,'port= %s^m',port); 
  50.  F_CLOSE(fd);
  51.  F_DELETE(file);
  52.  RETURN(0);
  53. }
  54.  
  55. // parse telnet info from url
  56. FUNC parse_telnet(STR url, STR host, STR port, STR user, STR pass)
  57. {
  58.  INT div;
  59.  
  60.  user = pass = host = port = "";
  61.  
  62.  div = STR_INDEX("://",url);
  63.  IF (div < 0) { RETURN(0) }
  64.  url = STR_MID(url,div+3);
  65.  
  66.  div = STR_INDEX("@",url);
  67.  IF (div) {
  68.   user = STR_LEFT(url,div);
  69.   url = STR_MID(url,div+1);
  70.   div = STR_INDEX(":",user);
  71.   IF (div > 0) {
  72.    pass = STR_MID(user,div+1);
  73.    user = STR_LEFT(user,div);
  74.   }
  75.  }
  76.  host = url;
  77.  div = STR_INDEX(":",host);
  78.  IF (div > 0) {
  79.   port = STR_MID(host,div+1);
  80.   host = STR_LEFT(host,div);
  81.  }
  82.  IF (STR_RIGHT(host,1) == "/") {
  83.   host = STR_LEFT(host,STR_LEN(host)-1);
  84.  }
  85.  RETURN;
  86. }
  87.  
  88. // telnet to a site
  89. FUNC telnet_to(STR host, STR port, STR user, STR pass)
  90. {
  91.  INT x;
  92.  STR file;
  93.  
  94.  WHILE (1) {
  95.   file = ".PREF:PT Telnet URL";
  96.   IF (IS_FILE(file)) { BREAK }
  97.   file = FN_GETPATH(5)+"{Telnet}";
  98.   IF (IS_FILE(file)) { BREAK }
  99.   RETURN(-1);
  100.  }
  101.  
  102.  x = NUM_STR(port);
  103.  IF (x == 0) { x = 23 }
  104.  port = STR_NUM(x);
  105.  
  106.  UI_OPEN(file);
  107.  UI_SET("Phone Number",STR_FORMAT("%s,%s",host,port));
  108.  UI_SET("Term Window Name",host);
  109.  UI_SET("Close Window After Connect","1");
  110.  UI_MENU("File:Save");
  111.  UI_CLICK("Retry");
  112.  
  113.  RETURN(0);
  114. }
  115.  
  116.